package com.cskaoyan.catmall.service.Impl;

import com.cskaoyan.catmall.dao.MarketCategoryMapper;
import com.cskaoyan.catmall.model.vo.CatalogCurrentWxVO;
import com.cskaoyan.catmall.model.vo.CatalogIndexWxVO;
import com.cskaoyan.catmall.model.vo.CategoryBeanWx;
import com.cskaoyan.catmall.service.CatalogServiceWx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Locale;

/**
 * @date: 2022-01-10-19-31
 * @author: ZYY
 * @description:
 */
@Service
public class CatalogServiceImpWx implements CatalogServiceWx {
    @Autowired
    MarketCategoryMapper categoryMapper;

    @Override
    public CatalogCurrentWxVO catalogCurrent(Integer id) {
        // 首先通过id查到目路
        CategoryBeanWx catalogBeanWx = categoryMapper.selectById(id);
        // 根据id查询子目录
        List<CategoryBeanWx> list = categoryMapper.selectByPid(id);

        // 将最终的结果封装到数据库
        CatalogCurrentWxVO data = new CatalogCurrentWxVO();
        data.setCurrentCategory(catalogBeanWx);
        data.setCurrentSubCategory(list);
        return data;
    }

    @Override
    public CatalogIndexWxVO catalogIndex() {
        //首先获得list页面的第一个目录
        CategoryBeanWx catalogBeanWx = categoryMapper.selectByLevelLimit();
        // 根据pid查询第一个目录的子目录
        List<CategoryBeanWx> subList = categoryMapper.selectByPid(catalogBeanWx.getId());
        // 查询所有的一级类目
        List<CategoryBeanWx> list = categoryMapper.selectByLevel();

        // 封装数据到输出对象中
        CatalogIndexWxVO data = new CatalogIndexWxVO();
        data.setCurrentCategory(catalogBeanWx);
        data.setCurrentSubCategory(subList);
        data.setCategoryList(list);
        return data;
    }
}